package com.ys.controller.api.overseas;

import com.ys.entity.overseas.TosPlatformInformation;
import com.ys.service.overseas.TosPlatformInformationService;
import com.ys.service.sys.CommonApiService;
import com.ys.vo.LayuiTableVoJA;
import com.ys.vo.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @Author: fxz
 * @CreateTime: 2024-12-17
 * @Description: HW平台信息维护
 * @Version: 1.5
 */
@CrossOrigin
@Controller
@RequestMapping("/api/inter/tosPlatformInformation")
public class ApiInterTosPlatformInformationController {

    @Autowired
    private TosPlatformInformationService tosPlatformInformationService;

    @Autowired
    private CommonApiService<TosPlatformInformation> commonApiService;


    @RequiresPermissions("tosPlatformInformation:view")
    @RequestMapping("/search")
    @ResponseBody
    public LayuiTableVoJA search(Model model, HttpServletRequest request, HttpServletResponse response,
                                 @ModelAttribute TosPlatformInformation cond
    ){

        cond.addLeftJoin("TS_UserChange U ON U.Id = A.CreateChangeId ")
                .addField("U.UserId + '/' + U.UserName AS createUser");//创建人
        return commonApiService.searchLay(cond);
    }


    /**
     * 新增
     */
    @RequestMapping("/toAdd")
    @ResponseBody
    @RequiresPermissions("tosPlatformInformation:add")
    public R add(@RequestParam Map<String, Object> params) {
        try {
            //修改
            return tosPlatformInformationService.add(params);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }

    /**
     * 编辑
     */
    @RequiresPermissions("tosPlatformInformation:edit")
    @PostMapping("/toEdit")
    @ResponseBody
    public R edit(@RequestParam Map<String, Object> params){
        try {
            return tosPlatformInformationService.edit(params);
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
    }



    /**
     * 彈出框查询
     */
    @RequestMapping("/searchByModal")
    @ResponseBody
    public LayuiTableVoJA searchByModal(Model model, HttpServletRequest request, HttpServletResponse response,
                                        @ModelAttribute TosPlatformInformation cond,String conditions
    ){
        try {

            cond.setStatus(1);//启用
            LayuiTableVoJA setList = commonApiService.searchLay(cond);
            return setList;
        }catch (Exception e){
            LayuiTableVoJA tableVoJA = new LayuiTableVoJA();
            tableVoJA.setCode(1);
            tableVoJA.setMsg("查询出错，请稍后重试！");
            return tableVoJA;
        }
    }

}
